package Threads;

public class ThreadCommunication {
    public static void main(String[] args) {

        Runnable runner = new Runner();
        Thread t1 = new Thread(runner);
        Thread t2 = new Thread(runner);

        t1.setName("线程1：");
        t2.setName("线程2：");

        t1.start();
        t2.start();

    }

}

class Runner implements Runnable {

    private int count = 100;

    public void run() {
        while (true) {
            synchronized (this) {
                notify();
                if (count > 0) {
                    System.out.println(Thread.currentThread().getName() + "count = " + count--);
                } else {
                    break;
                }
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
